home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group00b.txt
/
000102_icon-group-sender_Tue Oct 24 16:47:28 2000.msg
< prev
next >
Wrap
Internet Message Format
|
2001-01-03
|
3KB
Return-Path: <icon-group-sender>
Received: (from root@localhost)
by baskerville.CS.Arizona.EDU (8.11.1/8.11.1) id e9ONlLP25739
for icon-group-addresses; Tue, 24 Oct 2000 16:47:21 -0700 (MST)
Message-Id: <200010242347.e9ONlLP25739@baskerville.CS.Arizona.EDU>
Date: Tue, 24 Oct 2000 13:59:26 -0700
From: Steve Wampler <swampler@noao.edu>
X-Accept-Language: en
To: symbiot@my-deja.com, icon-group <icon-group@cs.arizona.edu>
Subject: Re: How to "declare" a string?
Errors-To: icon-group-errors@cs.arizona.edu
Status: RO
Content-Length: 2048
symbiot@my-deja.com wrote:
>
> Hi,
>
> Thanks for your response.
>
> I based my program on the same assumption you made concerning how ICON
> scan variables and assigns type according to usage (and even converts
> on the fly).
>
> But in the statement I listed, it seemed to barf because I was
> requiring it to create an indexed string.
>
> The line was, essentially,
>
> data[index] := .....results of some string operation....
>
> I even tried intially data with
>
> data := " "
>
> But that created a variable that was one cell in size. So when the
> abouve statement got to "index := 2", it barfed because the variable
> data wasn't large enough.
>
> So again I'm back to the quesiton, "How to 'declare' a string variable?"
>
There's probably some confusion over terminology here. There is no
such thing as a "string variable" in Icon (or an "integer variable",
nor any other "typed" variable.
Any variable in Icon can hold a value of any type. Think of a variable
as a bucket that you can place anything in. Initially it's empty,
so trying to subscript it generates an error because there nothing
there to subscript it. Similarly, when you put the (1-character long)
string " " into it, subscripting failed when you tried to go past the
end of the string.
You could, of course, put a much larger string into the variable. There
are any number of ways to do so, for example:
data := repl(" ",4096)
would put a string of 4,096 blanks into data.
However, that's probably not the best way to make use of Icon, it leads
to thinking in terms of the variables instead of the values themselves,
and generally results in more complicated code than is necessary.
You might try and rethink how you're approaching the problem and think
more in terms of what you want the resulting value to look like and how
you might transform the input value into that result. Several people
have made some good suggestions on how you might proceed in this way.
--
Steve Wampler- SOLIS Project, National Solar Observatory
swampler@noao.edu